package com.southwind.controller;

import com.southwind.form.SearchForm;
import com.southwind.service.MoveoutService;
import com.southwind.util.ResultVOUtil;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/moveout")
public class MoveoutController {

    @Autowired
    private MoveoutService moveoutService;

    /**
     * 分页显示迁出登记
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{page}/{size}")
    public ResultVO list(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return ResultVOUtil.success(this.moveoutService.list(page, size));
    }

    /**
     * 迁出登记搜索
     * @param searchForm
     * @return
     */
    @GetMapping("/search")
    public ResultVO search(SearchForm searchForm){
        return ResultVOUtil.success(this.moveoutService.search(searchForm));
    }

    /**
     *学生迁出登记提交
     * @param id
     * @param reason
     * @return
     */
    @PutMapping("/moveout/{id}/{reason}")
    public ResultVO moveout(@PathVariable("id") Integer id,@PathVariable("reason") String reason){
        Boolean moveout = this.moveoutService.moveout(id, reason);
        if(!moveout) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    /**
     * 迁出记录分页展示
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/moveoutList/{page}/{size}")
    public ResultVO moveoutList(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return ResultVOUtil.success(this.moveoutService.moveoutList(page, size));
    }

    /**
     *迁出记录搜索
     * @param searchForm
     * @return
     */
    @GetMapping("/moveoutSearch")
    public ResultVO moveoutSearch(SearchForm searchForm){
        return ResultVOUtil.success(this.moveoutService.moveoutSearch(searchForm));
    }
}

